//
//  HeaderView.m
//  Marketing
//
//  Created by Hanen 3G 01 on 16/5/17.
//  Copyright © 2016年 Hanen 3G 01. All rights reserved.
//

#import "HeaderView.h"

@interface HeaderView ()
{
//    UIImageView    *arrowImage;
    
//    UILabel  *titleLabel;
//    UIButton  *chooseBtn;
//    UIButton  *coverBtn;
}
@end

@implementation HeaderView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self layOutViewsWithFrame:frame];
    }
    return self;
}

- (void)layOutViewsWithFrame:(CGRect)frame
{
    _arrowImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, frame.size.height / 2.0f - 7, 14, 14)];
//    arrowImage.image = [UIImage imageNamed:@"HY_list_icon_arrow_right.png"];
    [self addSubview:_arrowImage];
    
    _titleLabel= [ViewTool getLabelWith:CGRectMake(_arrowImage.maxX + 20, 0, 150, frame.size.height) WithTitle:nil WithFontSize:16.0f WithTitleColor:blackFontColor WithTextAlignment:NSTextAlignmentLeft];
    [self addSubview:_titleLabel];
    
    
    _chooseBtn = [[UIButton alloc] initWithFrame:CGRectMake(KSCreenW - 50 - 60, 0, 40, frame.size.height)];
    _chooseBtn.hidden = YES;
//    _chooseBtn.backgroundColor = NavBackColor;
    [_chooseBtn setTitle:@"全选" forState:UIControlStateNormal];
    [_chooseBtn setTitleColor:redBackColor forState:UIControlStateNormal];
    _chooseBtn.titleLabel.font = [UIFont systemFontOfSize:16.0f];
    [_chooseBtn addTarget:self action:@selector(clickSelectAll) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_chooseBtn];
    
    
   _coverBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width - 110, frame.size.height)];
    _coverBtn.backgroundColor = [UIColor clearColor];
//    coverBtn.selected = NO;
    [self addSubview:_coverBtn];
    [_coverBtn addTarget:self action:@selector(clickSectionHeader:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *lien = [ViewTool getLineViewWith:CGRectMake(0, frame.size.height - 1, frame.size.width, 1) withBackgroudColor:grayLineColor];
    [self addSubview:lien];
}
- (void)clickSelectAll
{
    if ([self.delegate respondsToSelector:@selector(clickSelectAllWithIndexPath:)]) {
        [self.delegate clickSelectAllWithIndexPath:self.section];
    }
}
- (void)clickSectionHeader:(UIButton *)sender
{
    
//    NSLog(@"headerView按钮点击选择状态%d",sender.selected);
//    if (sender.selected == NO) {
//        _chooseBtn.hidden = NO;
////        arrowImage.image = [UIImage imageNamed:@"HY_list_icon_arrow_down.png"];
//    }else{
//        _chooseBtn.hidden = YES;
////        arrowImage.image = [UIImage imageNamed:@"HY_list_icon_arrow_right.png"];
//    }
    
    if ([self.delegate respondsToSelector:@selector(clickSectionWithIndexPath: with:)]) {
        [self.delegate clickSectionWithIndexPath:self.section with:!sender.selected ? YES : NO];
    }
//    sender.selected = !sender.selected;
    
     NSLog(@"headerView按钮点击选择状态%d",sender.selected);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
